package com.reremouse.rerebbs.web.mb.mag;

import com.reremouse.model.SystemEmailBoxModel;
import com.reremouse.rerebbs.dao.ISystemEmailBoxDAO;
import com.reremouse.util.SpringHelper;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.event.ActionEvent;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@ManagedBean
@ViewScoped
public class EditSystemEmailBox
        implements Serializable {
    ISystemEmailBoxDAO systemEmailBoxDAO = (ISystemEmailBoxDAO) SpringHelper.getSpringBean("SystemEmailBoxDAO");
    List<SystemEmailBoxModel> emailboxes = new ArrayList();
    SystemEmailBoxModel eb = new SystemEmailBoxModel();

    public SystemEmailBoxModel getEb() {
        return this.eb;
    }

    public void setEb(SystemEmailBoxModel eb) {
        this.eb = eb;
    }

    public List<SystemEmailBoxModel> getEmailboxes() {
        return this.emailboxes;
    }

    public void setEmailboxes(List<SystemEmailBoxModel> emailboxes) {
        this.emailboxes = emailboxes;
    }

    @PostConstruct
    public void init() {
        this.emailboxes = this.systemEmailBoxDAO.findAllEmailBox();
    }

    public void delEmailBox(ActionEvent ee) {
        UIComponent ui = ee.getComponent();
        SystemEmailBoxModel nm = null;
        while ((ui != null) && (!(ui instanceof UIData))) {
            ui = ui.getParent();
        }
        if ((ui != null) && ((ui instanceof UIData))) {
            Object rowData = ((UIData) ui).getRowData();
            if ((rowData instanceof SystemEmailBoxModel)) {
                nm = (SystemEmailBoxModel) rowData;
            }
        }
        this.emailboxes.remove(nm);
    }

    public void addItem(ActionEvent ee) {
        this.emailboxes.add(this.eb);
        this.eb = new SystemEmailBoxModel();
    }

    public String finish() {
        this.systemEmailBoxDAO.synEmailBox(this.emailboxes);
        return "SystemConfig";
    }
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.rerebbs.web.mb.mag.EditSystemEmailBox

 * JD-Core Version:    0.7.0.1

 */